From 665dff5cd1da55d1675e72e0d44590b9be920f16 Mon Sep 17 00:00:00 2001 From: "atse@norwich.uk.xensource.com" Date: Thu, 28 Sep 2006 12:23:21 +0100 Subject: [PATCH] [XM] Fix stray quotes in usage message in getlabel.py Fixed built-in function name conflict. Raise correct exceptions for when option is invalid to be properly reported by xm. Signed-off-by: Alastair Tse --- tools/python/xen/xm/getlabel.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tools/python/xen/xm/getlabel.py b/tools/python/xen/xm/getlabel.py index 28e4619f45..f86b798771 100644 --- a/tools/python/xen/xm/getlabel.py +++ b/tools/python/xen/xm/getlabel.py @@ -25,8 +25,9 @@ from xen.xm.opts import OptionError def help(): return """ - Usage: xm getlabel dom " - xm getlabel res \n" + Usage: xm getlabel dom + xm getlabel res + This program shows the label for a domain or resource.""" def get_resource_label(resource): @@ -37,7 +38,7 @@ def get_resource_label(resource): try: access_control = dictio.dict_read("resources", file) except: - security.err("Resource label file not found") + raise OptionError("Resource label file not found") # get the entry and print label if access_control.has_key(resource): @@ -45,23 +46,22 @@ def get_resource_label(resource): label = access_control[resource][1] print "policy="+policy+",label="+label else: - security.err("Resource not labeled") + raise security.ACMError("Resource not labeled") def get_domain_label(configfile): # open the domain config file fd = None - file = None if configfile[0] == '/': fd = open(configfile, "rb") else: for prefix in [".", "/etc/xen"]: - file = prefix + "/" + configfile - if os.path.isfile(file): - fd = open(file, "rb") + abs_file = prefix + "/" + configfile + if os.path.isfile(abs_file): + fd = open(abs_file, "rb") break if not fd: - security.err("Configuration file '"+configfile+"' not found.") + raise OptionError("Configuration file '%s' not found." % configfile) # read in the domain config file, finding the label line ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE) @@ -79,7 +79,7 @@ def get_domain_label(configfile): # send error message if we didn't find anything if acline == "": - security.err("Domain not labeled") + raise security.ACMError("Domain not labeled") # print out the label (title, data) = acline.split("=", 1) @@ -89,7 +89,7 @@ def get_domain_label(configfile): print data -def main (argv): +def main(argv): if len(argv) != 3: raise OptionError('Requires 2 arguments') @@ -103,6 +103,11 @@ def main (argv): raise OptionError('First subcommand argument must be "dom" or "res"') if __name__ == '__main__': - main(sys.argv) + try: + main(sys.argv) + except Exception, e: + sys.stderr.write('Error: %s\n' % str(e)) + sys.exit(-1) + -- 2.30.2